<?php
namespace App\Http\Controllers;
use App\Models\Comment;
use App\Models\Note;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class CommentController extends Controller
{
    public function index($noteId)
    {
        return Comment::where('note_id', $noteId)->with('user')->get();
    }

    public function store(Request $request, $noteId)
    {
        $request->validate(['content' => 'required|max:500']);
        $note = Note::findOrFail($noteId);

        $comment = Comment::create([
            'user_id' => Auth::id(),
            'note_id' => $noteId,
            'content' => $request->content,
        ]);

        return response()->json($comment->load('user'), 201);
    }
}